<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page  import=" java.sql.*"%>
<%@page  import="javax.servlet.*"%>
<%@page  import="mybean.data.*"%><!-- 在使用bean的JSP中必须有相应的page指令，导入 -->
<jsp:useBean id="loginBean" class="mybean.data.login" scope="session"/><!--获得bean--loginbean存储着用户登录的信息  -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户主页</title>
	<link rel="stylesheet" type="text/css" href="css/reset.css">
	<link rel="stylesheet" type="text/css" href="css/common.css">
	<link rel="stylesheet" type="text/css" href="css/index-1.css">
</head>
<body>
	<div class="homepage-header public-header">
		<div class="home-header-box">
			<div class="homepage-logo"><img src="pictures/logo.jpg" class="header-logo"></div>
			<div class="container">
		    	<a href="homepage.jsp">首页 </a>
		    	<a href="borrow.jsp">找车</a>
		    	<a href="return.jsp">还车</a>
		    	<label style="width: 250px;color: #004b97;">&nbsp;&nbsp;</label>	
  				<div class="dropdown" ><button class="dropbtn" onclick="myFunction()">
		   	 			<img src="pictures/person.ico"><img src="pictures/down.ico"></button>
		   	 			<%out.print(" <span style=\"color: white; font-size: 16px;\">"+loginBean.getLogname()+"&nbsp;&nbsp;已实名认证</span>");%>
    					<div class="dropdown-content" id="myDropdown">
      						<a href="changeInfo.jsp">个人信息</a>
      						<a href="lookMyOrder.jsp">我的订单</a>
      						<a href="returnDeposit.jsp">退回押金</a>
      						<a href="exitServlet">退出登录</a>
    					</div>  					
  				</div>
  			</div> 
		</div>
	</div>
	<div class="slideshow-container2"><!-- 幻灯片 -->
  		<div class="mySlides fade">
    		<div class="numbertext">1 / 3</div>
    		<img src="pictures/move7.jpg" style="width:100%">
  		</div>
  	
  		<div class="mySlides fade">
    		<div class="numbertext">2 / 3</div>
    		<img src="pictures/move4.jpg" style="width:100%">
  		</div>
 
  		<div class="mySlides fade">
    		<div class="numbertext">3 / 3</div>
    		<img src="pictures/img3.jpg" style="width:100%">
 		</div>
 
 		<a class="prev" onclick="plusSlides(-1)">❮</a>
  		<a class="next" onclick="plusSlides(1)">❯</a>
	</div>
	<div style="text-align:center">
  		<span class="dot" onclick="currentSlide(1)"></span> 
  		<span class="dot" onclick="currentSlide(2)"></span> 
 		<span class="dot" onclick="currentSlide(3)"></span> 
	</div>
	<!-- 图片滚动条 -->
	<center>  
    <div id="bg">  
        <div id="sm"> <!--滚动div-->  
                <table> <tr> <!--外表格1x2,且第2单元格是空的-->  
                        <td id="Pic1">
                        	<table><tr>   <!--内表格1x4,存放4张图片-->                                   
                                	<td><img src="pictures/move9.jpg" onmouseover="mouseover(this)" onmouseout="mouseout(this)"/></td>  
                                    <td><img src="pictures/warn.jpg"  onmouseover="mouseover(this)" onmouseout="mouseout(this)"/></td>  
                                    <td><img src="pictures/warn1.jpg" onmouseover="mouseover(this)" onmouseout="mouseout(this)"/></td>  
                                    <td><img src="pictures/warn2.jpg" onmouseover="mouseover(this)" onmouseout="mouseout(this)"/></td>                     
                                </tr></table>  
                       </td>  
                       <td id="Pic2"></td> </tr>  
                </table>  
        </div>  
    </div>  
	</center>  
	<script type="text/javascript">
	/* 点击按钮，下拉菜单在 显示/隐藏 之间切换 */
	function myFunction() {
	    document.getElementById("myDropdown").classList.toggle("show");
	}
	// 点击下拉菜单以外区域隐藏
	window.onclick = function(e) {
	  if (!e.target.matches('.dropbtn')) {
	    var myDropdown = document.getElementById("myDropdown");
	      if (myDropdown.classList.contains('show')) {
	        myDropdown.classList.remove('show');
	      }
	  }
	}
	//手动切换幻灯片
	 var slideIndex = 1;
	showSlides(slideIndex);
	 
	function plusSlides(n) {
	  showSlides(slideIndex += n);
	}	 
	function currentSlide(n) {
	  showSlides(slideIndex = n);
	}
	function showSlides(n) {
	  var i;
	  var slides = document.getElementsByClassName("mySlides");
	  var dots = document.getElementsByClassName("dot");
	  if (n > slides.length) {slideIndex = 1} 
	  if (n < 1) {slideIndex = slides.length}
	 for (i = 0; i < slides.length; i++) {
	      slides[i].style.display = "none"; 
	  }
	  for (i = 0; i < dots.length; i++) {
	    dots[i].className = dots[i].className.replace(" active", "");
	  } 
	 slides[slideIndex-1].style.display = "block";
	  dots[slideIndex-1].className += " active";  	 
	}
	//滚动条
	 Pic2.innerHTML=Pic1.innerHTML;//复制一组图片，但被隐藏  
    function scrolltoleft(){//定义向左移动的方法  
        sm.scrollLeft++;//改变层的水平坐标，实现向左移动  
        if(sm.scrollLeft>=Pic1.scrollWidth)//需要复位  
            sm.scrollLeft=0;//层的位置复位，浏览器窗口的宽度有限的  
    }  
      
    var MyMar=setInterval(scrolltoleft,40); //定时器，方法名后不可加()        
    function mouseover(x){//鼠标指到图片上          
        x.style.cursor="pointer"  
    }    
    //两面两行是用方法响应对象的事件  
    sm.onmouseover=function(){//匿名方法（函数）  
        clearInterval(MyMar);////鼠标指到图片上  ，停止滚动  
    }  
      
    sm.onmouseout=function(){  
        MyMar = setInterval(scrolltoleft,40);//移开鼠标，继续滚动  
    }  
	</script>
	<!-- 根据用户的用户名，获取用户的信息,并存入loginBean中-->					
	<%	loginBean = (login)session.getAttribute("loginBean");
		boolean b=loginBean==null || loginBean.getLogname()==null || loginBean.getLogname().length()==0;
		if(b) {
			out.println("<script language = javascript>alert('请重新登录!');");
			out.println("location.href='index.jsp'</script>");
			return;
		}
		String nickname = loginBean.getLogname();//获取用户账户
		//System.out.println(username);
		String id="",money="",tel="",credict="",deposit="",realname="";
		Connection con;
	    Statement sql;
		ResultSet rs;
		String driverName="com.mysql.jdbc.Driver",
			   url = "jdbc:mysql://127.0.0.1:3306/bike?&useSSL=false&serverTimezone=GMT%2B8",
			   condition = "select * from user where Nickname='"+nickname+"'";
		try {//加载驱动
			Class.forName("com.mysql.jdbc.Driver");
		}
		catch(Exception e) {}
		try {//连接数据库
			con = DriverManager.getConnection(url,"root","744615");
			//System.out.println("连接数据库成功");
			sql=con.createStatement();
			rs = sql.executeQuery(condition);
			if (rs.next()==true) {
			id = rs.getString("Userid");
				tel = rs.getString("Utel");
				money = rs.getString("Umoney");
				credict = rs.getString("Ucredit");
				deposit = rs.getString("Udeposit");	
				realname = rs.getString("Uname");
				if(money==null)money="0";
				if(credict==null)credict="0";
				if(deposit==null)deposit="0";
			}
			if (rs != null) {
				rs.close();
				rs = null;
			}
			if (sql != null) {
				sql.close();
				sql = null;
			}
			if (con != null) {
		   	 	con.close();
		    	con = null;
			}
		}
		catch (SQLException e) {}
		try {
			//数据模型存储用户的信息
			loginBean.setID(id);
			loginBean.setcredict(credict);
			loginBean.setdeposit(deposit);
			loginBean.setmoney(money);
			loginBean.setPhone(tel);
			loginBean.setRealname(realname);
		}
		catch(Exception EE) {
			System.out.println(EE);
		}
		%>	
		<!--页面底部-->
		<!--所以的页面底部都一样，用一个文本文件存储，所有JSP文件使用嵌入-->
		<%@ include file="footer.txt" %>
</body>
</html>